package component.security.hardware;

import java.util.Vector;

/**
 * 取得网卡Mac地址的工具类
 *
 */
public class MacUtil {
	public static String getWinMacInfo() {
		String address = "";
		Vector vec = Shell.execute("ipconfig /all");
		String str ;
		for (int ii=0; ii<vec.size(); ii++) {
			str = (String)vec.get(ii);
			String strlow = str.toLowerCase();
			if (strlow.indexOf("physical address") == -1) {
				continue;
			}
			int index = str.indexOf(":");
			if (index > 0) {
				return str.substring(index + 1).trim();
			}
		}
		return address;
	}
	
	public static String getLinuxMacInfo() {
		String address = "";
		Vector vec = Shell.execute("ifconfig");
		String str ;
		for (int ii=0; ii<vec.size(); ii++) {
			str = (String)vec.get(ii);	
			int index = str.indexOf("硬件地址");
			if (index > 0) {
				return str.substring(index + 4).trim();
			} else {
				index = str.indexOf("HWaddr");
				if (index > 0){
					return str.substring(index + 6).trim();
				}
			}
		}
		return address;
		
	}
}
